/***************************************************************************//**
 * @file CGI/HazeScene.cpp
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2014 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef HAZE_SCENE_CPP
#define HAZE_SCENE_CPP
#endif

////////////////////////////////////////////////////////////////////////////////

#include <CGI/HazeScene.h>
#include <CGI/NodeCallback.h>

////////////////////////////////////////////////////////////////////////////////

HazeScene::HazeScene( CGI_Data *data ) :
    m_data ( data ),

    m_scenery  ( 0 ),
    m_aircraft ( 0 )
{
    m_hazeSceneGroup = new osg::Group();
    m_hazeSceneGroup->setName( "HazeSceneGroup" );

    m_scenery  = new Scenery  ( m_data );
    m_aircraft = new Aircraft ( m_data );

    m_hazeSceneGroup->addChild( m_scenery  ->getSceneryGroup()  .get() );
    m_hazeSceneGroup->addChild( m_aircraft ->getAircraftGroup() .get() );

    m_hazeSceneData = new DataTypeHazeScene( m_hazeSceneGroup.get() );

    m_hazeSceneGroup->setUserData( m_hazeSceneData.get() );
    m_hazeSceneGroup->setUpdateCallback( new NodeCallback<DataTypeHazeScene> );
}

////////////////////////////////////////////////////////////////////////////////

HazeScene::~HazeScene()
{
    if ( m_scenery  ) delete m_scenery;  m_scenery  = 0;
    if ( m_aircraft ) delete m_aircraft; m_aircraft = 0;
}

////////////////////////////////////////////////////////////////////////////////

void HazeScene::update()
{
    ////////////////////////////////////////
    if ( m_scenery  ) m_scenery  ->update();
    if ( m_aircraft ) m_aircraft ->update();
    ////////////////////////////////////////

#   ifndef MSCSIM_OSGEPHEMERIS
    m_hazeSceneData->setElevation( m_data->sunData.elevation );
#   endif
}
